<?php
require_once realpath(dirname(__FILE__) . '//..//..//pages.php');
require_once CLASS_RECORD;

/**
 * Description of Classe
 *
 * @author Andrea Cantafio
 */
class Classe extends Record {

    public function __construct ($values) {
        $data = array ();
        if (is_array ($values)) {
            foreach ($values as $key => $value) {
                $add = true;
                switch ($key) {
                    case 'ID':
                    case 'nome':
                        break;
                    default:
                        $add = false;
                }
                if ($add) {
                    $data[$key] = $value;
                }
            }
        }
        $this->required[] = 'nome';
        parent::__construct ('classe', $data);
    }
    
    public function delete ($where = null) {
        require_once CLASS_STUDENTE;
        $db = openConnection();
        $result = $db->select(array ('studente', 'frequenta'), 'studente.ID', 'frequenta.IDstudente=studente.ID AND frequenta.IDclasse=' . $this->values['ID']);
        while ($row = $db->fetchAssoc ($result)) {
            $studente = new Studente (array ('ID' => $row['ID']));
            $studente->delete ();
        }
        return parent::delete ($where);
    }
    
}

?>
